<!doctype html>
<html  class="x-admin-sm">
<head>
	<meta charset="UTF-8">
	<link rel="icon" href="image/turtleShell.png" type="image/x-icon">
	<title>后台管理系统登陆界面</title>
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" href="css/login/font.css">
	<link rel="stylesheet" href="css/login/xadmin.css">
    <script type="text/javascript" src="js/jquery-3.2.1.min.js"></script>
    <script src="lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/login/xadmin.js"></script>
    <script type="text/javascript" src="js/login/cookie.js"></script>
	<script type="text/javascript" src="js/common.js"></script>
	<script type="text/javascript" src="js/core.js"></script>
	<script type="text/javascript" src="js/jsencrypt.min.js"></script>
	<style type="text/css">
		#login-foot {
			margin-top: 17.6%;
			text-align: center;
			font-size: 12px;
		}
	</style>
</head>
<body class="login-bg">
    <input type="hidden" id="rsa_public_key">
    <div class="login layui-anim layui-anim-up">
        <div class="message">曳尾后台管理系统</div>
        <div id="darkbannerwrap"></div>
        
        <form method="post" class="layui-form" >
            <input id="login_id" name="username" placeholder="请输入账号"  type="text" class="layui-input" >
            <hr class="hr15">
            <input id="login_password" name="password" placeholder="请输入密码"  type="password" class="layui-input">
            <hr class="hr15">
            <div style="height: 13.6px;">
				<span id="errorMsg" style="color: red;height: 13.6px;"></span>
            </div>
            <!-- <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit"> -->
            <button type="button" id="login" class="layui-btn layui-btn-fluid" style="height: 49px;width: 340px;margin-top: 23px;">登陆</button>
            <hr class="hr20" >
        </form>
    </div>
    <div id="login-foot"><a href="https://beian.miit.gov.cn" target="_blank">皖ICP备2021018259号-1</a></div>

    <script>
    	$(function(){
    		$.ajax({
				type : 'get',
	        	url : access_url+'/auth/login/getrsapubkey',
	        	success : function(data){
	        		if(200==data.code){
	        			//console.log("publicKey",data.retdata);
	        			$('#rsa_public_key').val(data.retdata);
	        			return;
	        		}
	        		$('#errorMsg').text(data.msg);
	        	}
			})
    		wxAuthor();
    	})
    
	    $('#login').click(function(){
	    	login();
	    })
	    
	    $('#login_id,#login_password').keydown(function(e){
	    	pressEnter(e);
	    })
	    
	    /* 按回车键触发登陆方法 */
	    function pressEnter(e){
	    	/* 13代表enter键 */
	    	if(13==e.keyCode){
	    		login();
	    	}
	    }
	    
	    /** 登陆的方法 **/
	    function login(){
	    	$('#errorMsg').html('');
	    	var login_id = $('#login_id').val();
			var login_password = $('#login_password').val();
			
			if(null==login_id||''==login_id){
				layer.tips('请输入账号','#login_id');
				return;
			}
			if(null==login_password||''==login_password){
				layer.tips('请输入密码','#login_password');
				return;
			}
			
			let pubKey = $("#rsa_public_key").val();
			
			var encrypt = new JSEncrypt();
			encrypt.setPublicKey(pubKey);
			login_password = encrypt.encrypt(login_password);
			
			$('#login').attr("disabled","disabled");
			$('#login').css("background-color","#D9D9D9");
			$.ajax({
				type : 'post',
	        	url : access_url+'/auth/login/logon',
	        	contentType : 'application/json;charset=utf-8',
	        	data : JSON.stringify({
	        		login_id : login_id
	        		,login_password : login_password
	        		,rsaPubKey : pubKey
	        	}),
	        	success : function(data){
	        		if(200==data.code){
	        			console.log("token",data.retdata);
	        			/* sessionStorage.setItem("token",data.retdata);
		        		console.log('把token放入浏览器缓存'); */
	        			//layer.msg(data.msg);
	        			location.href='index.html'
	        			//window.location.reload();
	        			return;
	        		}
	        		//layer.msg(data.msg,{icon:2});
	        		$('#errorMsg').text(data.msg);
	        		$('#login').removeAttr("disabled");
			        $('#login').css("background-color","#009688");
	        	}
			})
	    }
	    
	    function wxAuthor() {
	    	console.log('进入微信认证')
	    	let code = getQueryString("code")
	    	let state = getQueryString("state")
	    	if(isNull(code) || isNull(state)){
	    		console.log('不是从微信公众号登录,中止微信认证')
	    		return;
	    	}
	    	$.ajax({
				type : 'get',
				data : {
					code : code,
					state : state
				},
	        	url : access_url+'/wx/getwxuserinfo',
	        	success : function(data){
	        		console.log("author2Data",data);
	        	}
			})
	    }
    </script>
    
</body>
</html>